package com.mf.springboot.backend.commonModule.common;

import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * Created by java_zw on 2017/3/6.
 */
public class CryptographyUtil {

    public static final String PASSWORD_SALT = "wh_traffic_manage_platform";


    /**
     * base64加密xxx
     * @param str
     * @return
     */
    public static String encBase64(String str){
        return Base64.encodeToString(str.getBytes());
    }

    /**
     * base64解密
     * @param str
     * @return
     */
    public static String decBase64(String str){
        return Base64.decodeToString(str);
    }

    /**
     * Md5加密      Shiro中自带MD5没有解密
     * @param str   要加密的值
     * @param salt  盐值
     * @return
     */
    public static String md5(String str,String salt){
        return new Md5Hash(str,salt).toString();
    }

    /**
     * Md5加密      Shiro中自带MD5没有解密
     * @param str   要加密的值
     * @return
     */
    public static String getMD5(String str){
        return new Md5Hash(str,PASSWORD_SALT).toString();
    }



    public static void main(String[] args) {
          String password="admin";
//        System.out.println("Base64加密："+CryptographyUtil.encBase64(password));
//        System.out.println("Base64解密："+CryptographyUtil.decBase64(CryptographyUtil.encBase64(password)));
//        //MD5加密应用到实际项目中开发比如：注册提交数据是对密码进行MD5加密就会得到一串这样的70f57208b804bd90d51fdac84afe6472字符串储存到数据库
//        //这就是MD5加密过后的密码，做用户验证是把数据库获取到的密码在对比
//        System.out.println("Md5加密："+CryptographyUtil.md5("admin", PASSWORD_SALT));
//        TaskManagement taskManagement = new TaskManagement();
//        taskManagement.setCompleteFile("xxx");
//        taskManagement.setCompleteSituation("cccc");
//        taskManagement.setCompleteTime(new Date());
//        TaskManagement taskManagement1 = new TaskManagement();
//        ObjectForUpdate.updateForObject(taskManagement,taskManagement1);
//        System.out.println("===-------------==="+taskManagement1.getCompleteFile());
        System.out.println(getMD5("123"));
        System.out.println("============"+md5("1231231231ddddddD3rDZXZdQLiITLcBd6G4MfL6uxcC8Ls6Ecomxcdm7mrr1rNNF3KK8TN13PH+p/Gp3LVybYlVPHeO\r\nxw4R0QMzRfMRVaZTZyjF1cgxPjOx7+kAZqBuIjKyr62X8WtlSRk/+tC32rubNoK5reBlMaHCchZM\r\n0KEIsuf8gaYFTAQHvBM=1cd46f7a-101b-4a98-8c61-ab76a0e2f5d6106.651957076726.62458569972017-01-01","mufengTech"));




    }
}
